// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/base/api/EventInfoApi'

import ComClass from '@api/ComQuery'
import ListClass from '@api/base/model/EventInfoReq'
import DelClass from '@api/base/model/EventInfoDeleteReq'
import BaseClass from '@api/base/model/EventInfoDto'

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  validParam(param) {
    return !CORE.isEmpty(param.eventLevelCodeList)
  },
  async getList(param, TIP = '查询列表') {
    const DTO = CORE.grpcDTO(ListClass, param, COM, [BaseClass, 'dto'])
    const resp = await CORE.grpc(TIP, CLIENT, 'eventInfoQuery', DTO)
    const count = { 1: resp.commonCount, 2: resp.majorCount, 3: resp.emergentCount }
    return [resp.comQuery.totalCount, resp.dto || [], count]
  },
  dealList([obj], { state: { MAP } }) {
    if (MAP.COUNT) MAP.COUNT = obj || {}
  },

  // —————————————————————————————— 删 —————————————————————————————— //

  async del({ id }, TIP = '删除') {
    const DTO = CORE.grpcDTO(DelClass, { ids: [id] })
    await CORE.grpc(TIP, CLIENT, 'eventInfoDelete', DTO)
    return CORE.grpcOK(TIP)
  },
}
